package com.pay.util;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.pay.beans.WxCustLoginStatusBean;
import com.pay.constants.RedisKeyConstants;

public class RedisCustUtil {
	private static Logger log = LoggerFactory.getLogger(RedisCustUtil.class);

	public static List<WxCustLoginStatusBean> getCustByOpenid(String openId,boolean isDefult){
		List<String> list = RedisUtil.hvals(RedisKeyConstants.MULT_ACCOUNT_OPENID_USERNOS + openId);
		String defultCustom = RedisUtil.getValue(RedisKeyConstants.MULT_ACCOUNT_DEFAULT_OPENID_USERNO+openId);
		List<WxCustLoginStatusBean>  wxList = new ArrayList<WxCustLoginStatusBean>();
		WxCustLoginStatusBean wxCustLoginStatusBean = null;
		for(String w : list){
			wxCustLoginStatusBean = JSON.parseObject(w, WxCustLoginStatusBean.class);
			if(wxCustLoginStatusBean.getCustomerNo().equals(defultCustom)){
				wxCustLoginStatusBean.setIsDefault("Y");
				if(isDefult){
					wxList.add(wxCustLoginStatusBean);
				}
			}else{
				wxCustLoginStatusBean.setIsDefault("N");
			}
			if(!isDefult){
				wxList.add(wxCustLoginStatusBean);
			}
		}
		log.info("opendId:"+openId+"获取缓存custNo（"+isDefult+"）");
		log.info("wxList.size():"+wxList.size());
		log.info("wxList.tojson:"+JSON.toJSONString(wxList));
		return wxList;
	}
	
	public static String getCustNoByOpenid(String openId){
		String defultCustom = RedisUtil.getValue(RedisKeyConstants.MULT_ACCOUNT_DEFAULT_OPENID_USERNO+openId);
		return defultCustom;
	}
	public static String getOpenidByCustNo(String custNo){
		return  RedisUtil.getValue(RedisKeyConstants.MULT_ACCOUNT_USERNO_OPENID+custNo);
	}
}
